public class Solution {
    int path;
    int len;
    int sum;

    public int subsetXORSum(int[] nums) {
        len = nums.length;

        dfs(nums, 0);

        return sum;
    }

    public void dfs(int[] nums, int pos) {
        if (pos == len) {
            sum += path;
            return;
        }

        //选
        path ^= nums[pos];
        dfs(nums, pos + 1);
        //回溯
        path ^= nums[pos];

        //不选
        dfs(nums, pos + 1);
    }

    public void dfs2(int[] nums, int pos) {
        sum += path;

        for (int i = pos; i < len; i++) {
            path ^= nums[i];
            dfs(nums, i + 1);
            //回溯
            path ^= nums[i];
        }
    }
}
